package com.surelution.lansao

class MemberAddress {

    static constraints = {
		unit nullable:true
		address nullable:true
		building nullable:true
    }
	
	Member member
	
	Building building
	String unit
	String address
	Boolean lastDelivery
	Boolean verified
	
	@Override
	public String toString() {
		return address + " " + unit;
	}

	public static MemberAddress findSuitableAddress(Member member) {
		def cri = createCriteria()
		def rt = cri.list() {
			eq('member',member)
			order('verified')
		}
		if(rt && rt.size() > 0) {
			return rt.get(0)
		} else {
			return null
		}
	}
}
